package com.k7k7.client;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 接收客户端的线程
 *
 * @author Administrator
 */
public class UserClientThread extends Thread {
	private ServerSocket ss;
	private Class cl;

	public UserClientThread(int clientPort, Class cl) throws IOException {
		this.cl = cl;
		ss = new ServerSocket(clientPort);
	}

	@Override
	public void run() {
		try {
			Socket client = ss.accept();
			Constructor[] ccs = cl.getConstructors();
			BaseClient ccl = (BaseClient) ccs[0].newInstance(client);
			ccl.start();
		} catch (Exception e) {
			System.err.print("新建客户端连接错误");
		}
	}
}
